package velocity;


import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.VelocityEngine;

import java.io.*;
import java.util.Properties;

/**
 * function
 * Created by Administrator on 2016/12/2.
 */
public class VelocityLongUtil {
    private String velocityPath ;
    private String velocityDestination;

    public VelocityLongUtil(String velocityPath, String velocityDestination){
        this.velocityPath = velocityPath;
        this.velocityDestination = velocityDestination;
    }

    public void generateByVelocity(){
        VelocityEngine ve = new VelocityEngine();

        ve.setProperty(VelocityEngine.RUNTIME_LOG,"longLog");
        ve.setProperty("file.resource.loader.path", velocityPath);
        ve.init();

        VelocityContext vcontext = new VelocityContext();
        vcontext.put("hello","Helloworld!");
        Template template = null;

        try{
            template = ve.getTemplate("Entity.vm");
            Writer pw = new PrintWriter("E:\\workspace_idea\\longautotheme\\src\\test\\java\\velocity\\file\\longge.txt");
            template.merge(vcontext,pw);
           pw.flush();
//            System.out.println("template:"+pw);
        }
        catch(Exception e){
            e.printStackTrace();
        }
    }

    public String getVelocityPath() {
        return velocityPath;
    }

    public void setVelocityPath(String velocityPath) {
        this.velocityPath = velocityPath;
    }

    public String getVelocityDestination() {
        return velocityDestination;
    }

    public void setVelocityDestination(String velocityDestination) {
        this.velocityDestination = velocityDestination;
    }
}
